package service

import (
	"context"
	"xgs_kratos/app/users/internal/biz"

	pb "xgs_kratos/gen/users"
)

type UserService struct {
	pb.UnimplementedUserServer
	uc *biz.UserUsecase
}

func NewUserService(uc *biz.UserUsecase) *UserService {
	return &UserService{
		uc: uc,
	}
}

func (s *UserService) CreateUser(ctx context.Context, req *pb.CreateUserRequest) (*pb.CreateUserReply, error) {
	user, err := s.uc.CreateUser(ctx, &biz.User{})
	if err != nil {
		return nil, err

	}
	return &pb.CreateUserReply{
		Id: int32(user.Id),
	}, nil
}

//	func (s *UserService) UpdateUser(ctx context.Context, req *pb.UpdateUserRequest) (*pb.UpdateUserReply, error) {
//		return &pb.UpdateUserReply{}, nil
//	}
//
//	func (s *UserService) DeleteUser(ctx context.Context, req *pb.DeleteUserRequest) (*pb.DeleteUserReply, error) {
//		return &pb.DeleteUserReply{}, nil
//	}
//
//	func (s *UserService) GetUser(ctx context.Context, req *pb.GetUserRequest) (*pb.GetUserReply, error) {
//		return &pb.GetUserReply{}, nil
//	}
func (s *UserService) ListUser(ctx context.Context, req *pb.ListUserRequest) (*pb.ListUserReply, error) {
	user, err := s.uc.ListUser(ctx, &biz.User{})
	if err != nil {
		return nil, err

	}
	rs := make([]*pb.UserData, 0)
	for _, v := range user {
		rs = append(rs, &pb.UserData{
			Id: int32(v.Id),
		})
	}
	return &pb.ListUserReply{
		Users: rs,
	}, nil
}
